package com.otod.pm.prj.service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.otod.base.service.BaseService;
import com.otod.pm.prj.mapper.StepTpMapper;
import com.otod.pm.prj.mapper.TaskTpMapper;
import com.otod.pm.prj.vo.StepTpVo;


/**
 * 阶段管理
 * @author jqiu
 */
@Service
@Transactional(readOnly=true)
public class StepTpService extends BaseService {
	
	@Autowired
	StepTpMapper stepTpMapper;
	@Autowired
	TaskTpMapper taskTpMapper;
	
	/***
	 * 新增阶段
	 * @param StepTpVo
	 */
	@Transactional
	public StepTpVo insert(StepTpVo stepTpVo) {
		stepTpVo.setUuid(super.getUUID());
		stepTpMapper.insert(stepTpVo);
		return stepTpVo;
	}
	
	/**
	 * 修改
	 * @param map
	 */
	@Transactional
	public void update(Map<String, Object> map){
		stepTpMapper.update(map);
	}
	
	/**
	 * 删除
	 * @param id
	 */
	@Transactional
	public void deleteById(String id){
		stepTpMapper.deleteById(id);
		taskTpMapper.deleteByStepTpId(id);
	}
	
	/**
	 * 主键查询
	 * @param id
	 */
	public StepTpVo getById(String id){
		return stepTpMapper.getById(id);
	}
	
	/**
	 * 查询产品下所有有效果的阶段
	 * @param prjId 项目ID
	 */
	public List<StepTpVo> queryValidList(String tpId){
		Map<String,Object> param = new HashMap<String, Object>();
		param.put("tpId",tpId);
		return stepTpMapper.queryForList(param);
	}
	
}
